%% This m-file is to display the 2D raw data and save to  *.mat 
% The 1st step to analyze florescence data
% The next step is Flores_2D_display4pub.m for publication


close all
clear all
clc

DataFile='SMFe01.dat'


MCAfile={ 
    % 2D data (energy,qz, intensity)
    'SMFe01.dat.scan49.mca'; % NO KCl. FeCl3 40uM + SPM
    'SMFe01.dat.scan95.mca'; % + KCl (droplet in diffusion), FeCl3 40uM + SPM
    'SMFe01.dat.scan127.mca';% + KCl (droplet stable), FeCl3 40uM + SPM
    'SMFe01.dat.scan30.mca'; % Pure Water Subphase
    'SMFe01.dat.scan35.mca'; % Pure Water Subphase

      'SMFe01.dat.scan44.mca'; % Only Fe, No KCl, Before Reflec
      'SMFe01.dat.scan49.mca'; % Only Fe, No KCl, Before Reflec
      'SMFe01.dat.scan76.mca'; % Only Fe, No KCl, after Reflec
      'SMFe01.dat.scan81.mca'; % Only Fe, No KCl, after Reflec

      'SMFe01.dat.scan175.mca';  % 100 mM KCl, with Fe, before relfec
      'SMFe01.dat.scan180.mca';  % 100 mM KCl, with Fe, before relfec
      'SMFe01.dat.scan207.mca';  % 100 mM KCl, with Fe, after relfec
      'SMFe01.dat.scan212.mca';  % 100 mM KCl, with Fe, after relfec

       'SMFe01.dat.scan221.mca';  % 50 mM KCl, with Fe, before reflec
       'SMFe01.dat.scan226.mca';  % 50 mM KCl, with Fe, before reflec
       'SMFe01.dat.scan253.mca';  % 50 mM KCl, with Fe, after reflec
       'SMFe01.dat.scan258.mca';  % 50 mM KCl, with Fe, after reflec

        'SMFe01.dat.scan267.mca';   % 10 mM KCl, with Fe, before reflec
        'SMFe01.dat.scan272.mca';   % 10 mM KCl, with Fe, before reflec
        'SMFe01.dat.scan299.mca';   % 10 mM KCl, with Fe, after reflec
        'SMFe01.dat.scan304.mca';   % 10 mM KCl, with Fe, after reflec

        'SMFe01.dat.scan313.mca';  % 1 mM KCl, with Fe, before reflec
        'SMFe01.dat.scan318.mca';  % 1 mM KCl, with Fe, before reflec
        'SMFe01.dat.scan345.mca';  % 1 mM KCl, with Fe, after reflec
        'SMFe01.dat.scan350.mca';  % 1 mM KCl, with Fe, after reflec

          'SMFe01.dat.scan451.mca';  % 4 mM Fe, No KCl, pure subphase
          'SMFe01.dat.scan456.mca';  % 4 mM Fe, No KCl, pure subphase
          'SMFe01.dat.scan461.mca';  % 4 mM Fe, No KCl, pure subphase
          'SMFe01.dat.scan466.mca';  % 4 mM Fe, No KCl, pure subphase
          'SMFe01.dat.scan471.mca';  % 4 mM Fe, No KCl, pure subphase
          'SMFe01.dat.scan476.mca';  % 4 mM Fe, No KCl, pure subphase
          
    }

MONScanNum={
    49; % NO KCl, FeCl3 40uM + SPM
    95; % + KCl (droplet in diffusion), FeCl3 40uM + SPM
    127;% + KCl (droplet stable), FeCl3 40uM + SPM
    30; % Pure Water Subphase
    35; % Pure Water Subphase
      44; % Only Fe, No KCl, Before Reflec
      49; % Only Fe, No KCl, Before Reflec
      76; % Only Fe, No KCl, after Reflec
      81; % Only Fe, No KCl, after Reflec

     175;180;   %100 mM KCl, with Fe, before relfec
     207;212;  % 100 mM KCl, with Fe, after relfec

       221;226;  % 50 mM KCl, with Fe, before reflec
       253;258;  % 50 mM KCl, with Fe, after reflec

        267;272;   % 10 mM KCl, with Fe, before reflec
        299;304;    % 10 mM KCl, with Fe, after reflec

        313;318; % 1 mM KCl, with Fe, before reflec
        345;350;  % 1 mM KCl, with Fe, after reflec
       451;456;461;466;471;476; %  4 mM Fe, No KCl, pure subphase

    }

MATfile={
    'SMFe01_scan49_raw.mat';   % NO KCl, FeCl3 40uM + SPM
    'SMFe01_scan95_raw.mat';  % + KCl (droplet in diffusion), FeCl3 40uM + SPM
    'SMFe01_scan127_raw.mat'; % + KCl (droplet stable), FeCl3 40uM + SPM
    'SMFe01_scan30_raw.mat';  % Pure Water Subhpase
    'SMFe01_scan35_raw.mat';  % Pure Water Subphase

     'SMFe01_scan44_raw.mat'; % Only Fe, No KCl, Before Reflec
     'SMFe01_scan49_raw.mat'; % Only Fe, No KCl, Before Reflec
     'SMFe01_scan76_raw.mat'; % Only Fe, No KCl, after Reflec
     'SMFe01_scan81_raw.mat'; % Only Fe, No KCl, after Reflec

     'SMFe01_scan175_raw.mat';   %100 mM KCl, with Fe, before relfec 
     'SMFe01_scan180_raw.mat';   %100 mM KCl, with Fe, before relfec
     'SMFe01_scan207_raw.mat';   % 100 mM KCl, with Fe, after relfec
      'SMFe01_scan212_raw.mat';  % 100 mM KCl, with Fe, after relfec

        'SMFe01_scan221_raw.mat'; % 50 mM KCl, with Fe, before reflec
        'SMFe01_scan226_raw.mat'; % 50 mM KCl, with Fe, before reflec
        'SMFe01_scan253_raw.mat'; % 50 mM KCl, with Fe, after reflec
        'SMFe01_scan258_raw.mat'; % 50 mM KCl, with Fe, after reflec
      
        'SMFe01_scan267_raw.mat'; % 10 mM KCl, with Fe, after reflec
        'SMFe01_scan272_raw.mat'; % 10 mM KCl, with Fe, after reflec
        'SMFe01_scan299_raw.mat'; % 10 mM KCl, with Fe, after reflec
        'SMFe01_scan304_raw.mat'; % 10 mM KCl, with Fe, after reflec

        'SMFe01_scan313_raw.mat'; % 10 mM KCl, with Fe, after reflec
        'SMFe01_scan318_raw.mat'; % 10 mM KCl, with Fe, after reflec
        'SMFe01_scan345_raw.mat'; % 10 mM KCl, with Fe, after reflec
        'SMFe01_scan350_raw.mat'; % 10 mM KCl, with Fe, after reflec

           'SMFe01_scan451_raw.mat'; %  4 mM Fe, No KCl, pure subphase
           'SMFe01_scan456_raw.mat'; %  4 mM Fe, No KCl, pure subphase
           'SMFe01_scan461_raw.mat'; %  4 mM Fe, No KCl, pure subphase
           'SMFe01_scan466_raw.mat'; %  4 mM Fe, No KCl, pure subphase
           'SMFe01_scan471_raw.mat'; %  4 mM Fe, No KCl, pure subphase
           'SMFe01_scan476_raw.mat'; %  4 mM Fe, No KCl, pure subphase
           
    }

%%  To save the 2D data in a matrix in a MAT file and later to be reloaded
% use mcaread.m script version 1.0
% The 2D data 

close all
clc
CalibCoef=[0.0119,-0.0972];  % Channel->Energy calibration coefficients Ames 2016 new detector
for k=1:length(MCAfile)
    [mca,energy,qz,ct]=mcaread(MCAfile{k},CalibCoef);
    Mon_data=plcol(DataFile,MONScanNum{k},'MonitorA');
    mon=Mon_data'; % Row vector (each row element corresponds to a Qz);
    imagesc(qz,energy(100:1000),mca(100:1000,:));
    set(gca,'ydir','norm');
    pause(5)
    save(MATfile{k},'mca','energy','qz','ct','mon');
end









